﻿using System;
using System.Collections.Generic;
using System.Data;
using DAL;
using Entities;

namespace BLL
{
    public class BLL_Product
    {
        private DAL_Product dal_Product = new DAL_Product();

        public DataTable Get_Product_All()
        {
            return dal_Product.Get_Product_All();
        }

        public DataTable Get_Product_All_IsDisplay()
        {
            return dal_Product.Get_Product_All_IsDisplay();
        }

        public DataTable Get_GoodProduct()
        {
            return dal_Product.Get_GoodProduct();
        }

        public DataTable Get_Product_ID_MenuURL(int pID)
        {
            return dal_Product.Get_Product_ID_MenuURL(pID);
        }

        public DataTable Get_Product(Int64 pID)
        {
            return dal_Product.Get_Product(pID);
        }

        public DataTable Get_Product_TopNew()
        {
            return dal_Product.Get_Product_TopNew();
        }

        public DataTable Get_Product_Dynamic(string pCondition)
        {
            return dal_Product.Get_Product_Dynamic(pCondition);
        }

        public bool InsertUpdate_Product(Product pProduct)
        {
            return dal_Product.InsertUpdate_Product(pProduct);
        }

        public Int64 Get_Product_MaxID()
        {
            return dal_Product.Get_Product_MaxID();
        }

        public List<Product> Lst_Product(DataTable pdt)
        {
            List<Product> lstReturn = new List<Product>();
            if (pdt != null && pdt.Rows.Count > 0)
            {
                foreach (DataRow dr in pdt.Rows)
                {
                    Product product = new Product();
                    product.CODE = Convert.ToString(dr["CODE"]);
                    product.CREATE_DATE = (dr["CREATE_DATE"] == DBNull.Value ? DateTime.Now : Convert.ToDateTime(dr["CREATE_DATE"]));
                    product.DESCRIPTION = Convert.ToString(dr["DESCRIPTION"]); //(dr["ID_PARENT"] == DBNull.Value ? 0 : Convert.ToInt32(dr["ID_PARENT"]));
                    product.ID = Convert.ToInt32(dr["ID"]);
                    product.ID_MENUURL = Convert.ToInt32(dr["ID_MENUURL"]);
                    product.IMAGE_DIRECTORY = Convert.ToString(dr["IMAGE_DIRECTORY"]);
                    product.NAME = Convert.ToString(dr["NAME"]);
                    product.PRICE = Convert.ToInt64(dr["PRICE"]);

                    product.ORIGIN = Convert.ToString(dr["ORIGIN"]);
                    product.OTHER_NAME = Convert.ToString(dr["OTHER_NAME"]);
                    product.SALE = (dr["SALE"] == DBNull.Value) ? 0 : Convert.ToDecimal(dr["SALE"]);
                    product.STAT_STOCK = Convert.ToString(dr["STAT_STOCK"]);
                    product.STORAGE_TIME = Convert.ToString(dr["STORAGE_TIME"]);
                    product.IS_DISPLAY = Convert.ToString(dr["IS_DISPLAY"]);
                    product.WEIGHT = Convert.ToInt32(dr["WEIGHT"]);
                    product.SEQUENCE = (dr["SEQUENCE"] == DBNull.Value) ? 0 : Convert.ToInt32(dr["SEQUENCE"]);
                    lstReturn.Add(product);
                }
            }
            return lstReturn;
        }

        public bool DeleteProduct(Int64 pID)
        {
            return dal_Product.DeleteProduct(pID);
        }
    }
}
